package flex.cc.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import flex.cc.base.dto.LoginAuthDto;
import flex.cc.core.annotation.LogAnnotation;
import flex.cc.core.support.BaseController;
import flex.cc.system.entity.NoDisturbEntity;
import flex.cc.system.service.NoDisturbService;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * ${comments}
 *
 * @author jiayongchao
 * @email jiayongchao@sinosoft.com.cn
 * @date 2021-05-26 17:51:54
 */
@RestController
@RequestMapping("system/nodisturb")
public class NoDisturbController extends BaseController {

    @Autowired
    private NoDisturbService noDisturbService;


    /**
     * 新增免打扰信息
     * @param noDisturb
     * @return
     */
    @PostMapping(value = "/saveNoDisturb")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "新增免打扰信息")
    public Wrapper<String> saveNoDisturb(@ApiParam(name = "noDisturb", value = "新增免打扰信息")
                                             @RequestBody NoDisturbEntity noDisturb){
        logger.info(" 新增免打扰信息 noDisturb={}", noDisturb);
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        boolean result = noDisturbService.saveNoDisturb(noDisturb,loginAuthDto);
        if (result) {
            return WrapMapper.ok();
        }
        return WrapMapper.error();
    }


    /**
     * 更新免打扰信息
     * @param noDisturb
     * @return
     */
    @PostMapping(value = "/modifyNoDisturb")
    @LogAnnotation
    @ApiOperation(httpMethod = "POST", value = "更新免打扰信息")
    public Wrapper<String> modifyNoDisturb(@ApiParam(name = "noDisturb", value = "更新免打扰信息")
                                          @RequestBody NoDisturbEntity noDisturb){
        logger.info(" 更新免打扰信息 noDisturb={}", noDisturb);
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        boolean result = noDisturbService.modifyNoDisturb(noDisturb,loginAuthDto);
        if (result) {
            return WrapMapper.ok();
        }
        return WrapMapper.error();
    }

    /**
     * 更新免打扰状态
     * @param noDisturb
     * @return
     */
    @PostMapping(value = "/modifyStatusById")
    @ApiOperation(httpMethod = "POST", value = "更新免打扰状态")
    public Wrapper<String> modifyStatusById(@ApiParam(name = "noDisturb", value = "更新免打扰状态")
                                                @RequestBody NoDisturbEntity noDisturb){
        logger.info(" 通过Id更改短信模板状态 noDisturb={} status={}", noDisturb.getId(),noDisturb.getStatus());
        LoginAuthDto loginAuthDto = getLoginAuthDto();
        boolean result = noDisturbService.modifyStatusById(noDisturb,loginAuthDto);
        if (result) {
            return WrapMapper.ok();
        }
        return WrapMapper.error();
    }

    /**
     * 根据id删除免打扰信息
     * @return
     */
    @GetMapping(value = "/removeNoDisturbById/{noDisturbId}")
    @LogAnnotation
    @ApiOperation(httpMethod = "GET", value = "根据id删除免打扰信息")
    public Wrapper<String> removeNoDisturbById(@ApiParam(name = "noDisturb", value = "根据id删除免打扰信息")
                                              @PathVariable(value = "noDisturbId") Long noDisturbId){
        logger.info(" 根据id删除免打扰信息 noDisturbId={}", noDisturbId);
        boolean result = noDisturbService.removeNoDisturbById(noDisturbId);
        if (result) {
            return WrapMapper.ok();
        }
        return WrapMapper.error();
    }

    /**
     * 根据id查询免打扰信息
     * @return
     */
    @PostMapping(value = "/queryNoDisturbById/{noDisturbId}")
    @ApiOperation(httpMethod = "GET", value = "根据id查询短信模板接口")
    public Wrapper<NoDisturbEntity> queryNoDisturbById(@ApiParam(name = "noDisturb", value = "根据id查询免打扰信息")
                                                        @PathVariable Long noDisturbId){
        logger.info(" 根据id查询免打扰信息 noDisturbId={}", noDisturbId);
        NoDisturbEntity noDisturbEntity = noDisturbService.queryNoDisturbById(noDisturbId);
        return WrapMapper.ok(noDisturbEntity);
    }

    /**
     * 根据条件不分页查询免打扰集合
     * @return
     */
    @PostMapping(value = "/queryList")
    @ApiOperation(httpMethod = "POST", value = "根据条件不分页查询免打扰集合")
    public Wrapper<List<NoDisturbEntity>> queryList(@ApiParam(name = "noDisturb", value = "根据条件不分页查询免打扰集合")
                                                      @RequestBody NoDisturbEntity noDisturb){
        logger.info(" 根据条件不分页查询免打扰集合 noDisturb={}", noDisturb);
        List<NoDisturbEntity> list = noDisturbService.queryNoDisturbList(noDisturb);
        return WrapMapper.ok(list);
    }

    /**根据条件分页查询免打扰集合
     *
     * @return
     */
    @PostMapping(value = "/queryListWithPage")
    @ApiOperation(httpMethod = "POST", value = "根据条件分页查询免打扰集合")
    public Wrapper<IPage<NoDisturbEntity>> queryListWithPage(@ApiParam(name = "noDisturb", value = "根据条件分页查询免打扰集合")
                                                               @RequestBody NoDisturbEntity noDisturb){
        logger.info(" 根据条件分页查询免打扰集合 noDisturb={}", noDisturb);
        IPage<NoDisturbEntity> listPage = noDisturbService.queryNoDisturbListWithPage(noDisturb);
        return WrapMapper.ok(listPage);
    }



}
